
// Online C++ Compiler - Build, Compile and Run your C++ programs online in your favorite browser

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

int main() {
    std::vector<int> sp;
    for (int i = 2; i < 1000; ++i) {
        int f = 1;
        for (int j = 2; j < i / 2; ++j) {
            if (i % j == 0) {
                f = 0;
                break;
            }
        }
        if (f) {
            sp.push_back(i);
        }
    }

    std::vector<std::string> num = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};

    std::string ch;
    std::getline(std::cin, ch);
    std::replace(ch.begin(), ch.end(), '9', '&');
    std::replace(ch.begin(), ch.end(), '8', '&');
    std::replace(ch.begin(), ch.end(), '7', '&');
    std::replace(ch.begin(), ch.end(), '6', '&');
    std::replace(ch.begin(), ch.end(), '5', '&');
    std::replace(ch.begin(), ch.end(), '4', '&');
    std::replace(ch.begin(), ch.end(), '3', '&');
    std::replace(ch.begin(), ch.end(), '2', '&');
    std::replace(ch.begin(), ch.end(), '1', '&');
    std::replace(ch.begin(), ch.end(), '0', '&');

    if (ch.find('&') != std::string::npos || ch.find(' ') != 2) {
        std::cout << "Wrong input" << std::endl;
    } else {
        std::vector<std::string> d;
        std::string temp = "";
        for (char c : ch) {
            if (c == ' ') {
                d.push_back(temp);
                temp = "";
            } else {
                temp += c;
            }
        }
        d.push_back(temp);

        std::string newStr = "";
        for (const std::string& i : d) {
            newStr += std::to_string(std::distance(num.begin(), std::find(num.begin(), num.end(), i)));
        }
        int grate_maks = std::stoi(newStr);

        std::vector<std::pair<int, int>> razn;
        for (int i : sp) {
            razn.push_back({std::abs(grate_maks - i), i});
        }

        std::sort(razn.begin(), razn.end());
        std::cout << razn[0].second << std::endl;
    }

    return 0;
}